package deepbrain.simnetwork.mechanism;

import java.util.Set;

import deepbrain.simnetwork.network.Network;
import deepbrain.simnetwork.network.NetworkState;
import deepbrain.simnetwork.network.NodeState;
import deepbrain.simnetwork.structure.Connection;

/**
 * Copy Operation. The node with this mechanism only has one afferent
 * connection. And the node copies the state of that connection's another node.
 * 
 * @author Li Yang
 * @create 2009-2-25
 */
public class CopyOperation extends GenericMechanism {

	public NodeState nextNodeState(int node, Network network, NetworkState state) {
		Set<Connection<?>> connections = network.getAfferentConnections(node);
		if (connections.size() == 0)
			return state.getNodeState(node);
		else {
			for (Connection<?> connection : connections) {
				return state.getNodeState(connection.source);
			}
		}
		return state.getNodeState(node);
	}

	@Override
	public String toString() {
		return "Copy Operation";
	}

}
